package com.hunan.api.catv.service.biz.system;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hunan.api.catv.entity.ServiceResult;
import com.hunan.api.catv.entity.po.SystemRole;
import com.hunan.api.catv.entity.vo.SystemRoleVo;
import com.hunan.api.catv.service.ResultService;
import com.hunan.api.catv.service.impl.system.SystemRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

@CacheConfig(cacheNames = "SystemRoleBiz")
@Service
public class SystemRoleBiz extends ResultService {

    @Autowired
    SystemRoleService systemRoleService;

    public PageInfo<SystemRoleVo> page(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        SystemRole systemRole = new SystemRole();
        List<SystemRoleVo> list = systemRoleService.list(systemRole);
        return new PageInfo<SystemRoleVo>(list);
    }

    public SystemRoleVo info(Integer sysRoleId) {
        return systemRoleService.getById(sysRoleId);
    }

    public ServiceResult add(SystemRole systemRole) {
        return systemRoleService.add(systemRole);
    }

    public ServiceResult edit(SystemRole systemRole) {
        if (ObjectUtils.isEmpty(systemRole.getSysRoleId())) {
            return buildFail("", "id not null");
        }
        return systemRoleService.update(systemRole);
    }
}